#ifndef __PIC__FRAME__H__
#define __PIC__FRAME__H__

#include <mutex>
#include <stdlib.h>
#include "FrameCanvas.h"

namespace simple_renderer{

class PicFrame{
public:

    PicFrame() : _data_length(0),
                 _data_ptr(nullptr),
                 _pixels(nullptr), _pitches(nullptr){}

    PicFrame(int w, int h, FrameType type):
            _width(w), _height(h), _stride(_width), _frame_type(type), _texture_id(0), _data_ptr(nullptr),
            _pixels(nullptr), _pitches(nullptr){
    }

    PicFrame(int w, int h, int stride, FrameType type):
    _width(w), _height(h), _stride(stride), _frame_type(type), _texture_id(0), _data_ptr(nullptr),
    _pixels(nullptr), _pitches(nullptr){
    }

//    PicFrame(int w, int h, int texture_id, FrameType type):
//            _width(w), _height(h),_texture_id(texture_id), _frame_type(type), _data_ptr(nullptr){}

    virtual ~PicFrame(){
        Deinit();
    }

    void CopyData(int w, int h, FrameType type, uint8_t* data, int length);

    void CopyDataI420(int w, int h, FrameType type, uint8_t* data_y, int len_y, uint8_t* data_u, int len_u, uint8_t* data_v, int len_v);

    int GetTextureId(){
        return _textureId;
    }

    uint8_t **GetPixels() const {
        return _pixels;
    }
    uint16_t *GetPitches() const {
        return _pitches;
    }

    int GetWidth() const { return _width; }
    int GetHeight() const { return _height; }

    FrameType GetFrameType() const{ return _frame_type; }

    PicFrame& operator=(const PicFrame& picFrame);

protected:
    void Init();
    void Deinit();
protected:
    int _textureId;
    uint8_t *_data_ptr;

    int _width, _height, _stride;
    int _data_length;
    FrameType _frame_type;
    int _texture_id;

    uint8_t **_pixels;
    uint16_t *_pitches;
};
}
#endif